// run: $exec < input
#include <iostream>
#include <iomanip>
#include <utility>
#include <set>

int n, m;

template <class T>
T abs(T x) { if (x < 0) return -x; else return x; }

int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }

int main()
{
	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	int len = 13;
	for (int ti = 1; ti <= len; ti++) {
		for (int tj = 1; tj <= len; tj++) {
			std::set<std::pair<int, std::pair<int, int> > > all;
			std::cin >> n >> m;
			n = ti; m = tj;
			int ans = n + m;
			for (int i = 0; i < n * m; i++)
				for (int j = i + 1; j < n * m; j++) {
					int x1 = i / m, y1 = i % m;
					int x2 = j / m, y2 = j % m;
					if (x1 == x2 || y1 == y2) continue;
					int a = x2 - x1;
					int b = y1 - y2;
					int c = x1 * y2 - x2 * y1;
					int g = gcd(abs(a), abs(b));
					g = gcd(g, abs(c));
					a /= g; b /= g; c /= g;
					if (a < 0) { a = -a; b = -b; c = -c; }
					all.insert({a, {b, c}});
				}
			std::cout << std::setw(5) << ans + all.size() << ' ';
		}
		std::cout << '\n';
	}
}

